# $Id$
# Maintainer: Jan de Groot <jgc@archlinux.org>
# Contributor: Kritoke <kritoke@gamebox.net>

pkgbase=pycrypto
pkgname=('python2-crypto' 'python-crypto')
pkgver=2.6.1
pkgrel=5
arch=('i686' 'x86_64')
makedepends=('python2' 'python' 'gmp')
url="http://www.dlitz.net/software/pycrypto/"
license=('custom')
source=(http://ftp.dlitz.net/pub/dlitz/crypto/${pkgbase}/${pkgbase}-${pkgver}.tar.gz{,.asc}
        CVE-2013-7459.patch)
sha256sums=('f2ce1e989b272cfcb677616763e0a2e7ec659effa67a88aa92b3a65528f60a3c'
            'SKIP'
            '71310698e88a7b960467ec2107e0aaed1cb106d0d7b8b4f381ee9cdf4d9a7c7a')
validpgpkeys=('19E11FE8B3CFF273ED174A24928CEC1339C25CF7')  # Dwayne Litzenberger

prepare() {
  find ${pkgbase}-${pkgver}/LEGAL -type f -exec chmod 644 {} \;
  find ${pkgbase}-${pkgver}/LEGAL -type d -exec chmod 755 {} \;

  patch -d ${pkgbase}-${pkgver} -p1 < "${srcdir}/CVE-2013-7459.patch"
  cp -r ${pkgbase}-${pkgver} ${pkgbase}-${pkgver}-py3
}

build() {
  cd ${pkgbase}-${pkgver}
  python2 setup.py build

  cd ../${pkgbase}-${pkgver}-py3
  python setup.py build
}

package_python2-crypto() {
  pkgdesc="Collection of cryptographic algorithms and protocols, implemented for use from Python 2."
  depends=('python2' 'gmp')
  replaces=('pycrypto')
  conflicts=('pycrypto')
  provides=("pycrypto=${pkgver}")

  cd ${pkgbase}-${pkgver}
  python2 setup.py install --root="${pkgdir}" --optimize=1
  install -m755 -d "${pkgdir}/usr/share/licenses/${pkgname}"
  install -m644 COPYRIGHT "${pkgdir}/usr/share/licenses/${pkgname}/"
  cp -r LEGAL "${pkgdir}/usr/share/licenses/${pkgname}/"
}

package_python-crypto() {
  pkgdesc="Collection of cryptographic algorithms and protocols, implemented for use from Python 3."
  depends=('python' 'gmp')

  cd ${pkgbase}-${pkgver}-py3
  python setup.py install --root="${pkgdir}" --optimize=1
  install -m755 -d "${pkgdir}/usr/share/licenses/${pkgname}"
  install -m644 COPYRIGHT "${pkgdir}/usr/share/licenses/${pkgname}/"
  cp -r LEGAL "${pkgdir}/usr/share/licenses/${pkgname}/"
}

check() {
  cd ${pkgbase}-${pkgver}
  python2 setup.py test

  cd ../${pkgbase}-${pkgver}-py3
  python setup.py test
}
